package com.muyu.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.system.domain.SysUserPost;
import com.muyu.system.mapper.SysUserPostMapper;
import com.muyu.system.service.SysUserPostService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户与岗位关联业务实现层
 * @author dongzeliang
 * @version 1.0
 * @description: 用户与岗位关联业务实现层
 * @date 2025/2/13 21:51
 */
@Service
public class SysUserPostServiceImpl extends ServiceImpl<SysUserPostMapper, SysUserPost> implements SysUserPostService {
    /**
     * 通过用户ID删除用户与岗位关联
     *
     * @param userId 用户ID
     */
    @Override
    public void deleteUserPostByUserId(Long userId) {
        LambdaQueryWrapper<SysUserPost> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysUserPost::getUserId, userId);
        this.remove(lambdaQueryWrapper);
    }

    /**
     * 批量删除用户与岗位关联
     *
     * @param userIds 用户ID集合
     */
    @Override
    public void deleteUserPost(List<Long> userIds) {

        LambdaQueryWrapper<SysUserPost> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(SysUserPost::getUserId, userIds);
        this.remove(lambdaQueryWrapper);
    }

    /**
     * 通过岗位ID查询岗位使用数量
     *
     * @param postId 岗位ID
     * @return 使用数量
     */
    @Override
    public long countUserPostById(Long postId) {
        LambdaQueryWrapper<SysUserPost> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysUserPost::getPostId, postId);
        return this.count(lambdaQueryWrapper);
    }
}
